package com.aaa.tmr.controller;

import com.aaa.tmr.entity.Upload;
import com.aaa.tmr.service.UploadService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;

import javax.annotation.Resource;

/**
 * (Upload)表控制层
 *
 * @author makejava
 * @since 2021-03-24 11:04:43
 */
@Controller
@RequestMapping("upload")
public class UploadController {
    /**
     * 服务对象
     */
    @Resource
    private UploadService uploadService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Upload selectOne(Integer id) {
        return this.uploadService.queryById(id);
    }

    /**
     * 跳转字典类型分页列表页面
     *
     * @return 列表页面
     */
    @RequestMapping("toUpload")
    public String toUpload() {
        return "back/upload-page";
    }

    /**
     * 分页查询方法
     *
     * @param page
     * @param limit
     * @param upload
     * @return
     */
    @ResponseBody
    @RequestMapping("queryAll")
    public Result<java.util.List> queryAll(Integer page, Integer limit, Upload upload) {
        PageInfo pageInfo = uploadService.queryAll(page, limit, upload);
        return new Result<>(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(), pageInfo.getList());
    }

    /**
     * 新增数据
     *
     * @param upload 实例对象
     * @return 实例对象
     */
    @RequestMapping("insert")
    @ResponseBody
    public Result<Upload> insert(Upload upload) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.uploadService.insert(upload));
    }

    /**
     * 修改数据
     *
     * @param upload 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    @ResponseBody
    public Result<Upload> update(Upload upload) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.uploadService.update(upload));
    }

    /**
     * 通过主键删除数据
     *
     * @param uploadId 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    @ResponseBody
    public Result<Boolean> deleteById(Integer uploadId) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.uploadService.deleteById(uploadId));
    }

    /**
     * 通过主键删除数据
     *
     * @param uploadIds 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteByIds")
    @ResponseBody
    public Result<Boolean> deleteByIds(Integer uploadIds) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.uploadService.deleteById(uploadIds));
    }

}
